// 资源目录管理数据模型

// 资源分类
export enum ResourceCategory {
  BUSINESS = 'BUSINESS', // 业务资源
  TECHNICAL = 'TECHNICAL', // 技术资源
}

// 业务资源类型
export enum BusinessResourceType {
  COURSE = 'COURSE', // 课程
  EMPLOYEE = 'EMPLOYEE', // 员工
  EQUIPMENT = 'EQUIPMENT', // 设备
  EXPERT = 'EXPERT', // 专家
  INVENTORY = 'INVENTORY', // 库存
  MATERIAL = 'MATERIAL', // 材料
  ROOM = 'ROOM', // 房间
  SPACE = 'SPACE', // 空间
  STAFF = 'STAFF', // 工作人员
  SUPPLY = 'SUPPLY', // 用品
  TOOL = 'TOOL', // 工具
  TRAINING = 'TRAINING', // 培训
  VEHICLE = 'VEHICLE', // 车辆
  VENUE = 'VENUE', // 场地
  WORKSHOP = 'WORKSHOP', // 工作坊
}

// 技术资源类型
export enum TechnicalResourceType {
  API_ENDPOINT = 'API_ENDPOINT', // 接口端点
  API_SCHEMA = 'API_SCHEMA', // 接口模式
  API_TEMPLATE = 'API_TEMPLATE', // 接口模板
  CHART_TEMPLATE = 'CHART_TEMPLATE', // 图表模板
  DASHBOARD = 'DASHBOARD', // 仪表盘
  FORM_FIELD = 'FORM_FIELD', // 表单字段
  FORM_TEMPLATE = 'FORM_TEMPLATE', // 表单模板
  FORM_VALIDATION = 'FORM_VALIDATION', // 表单验证
  REPORT_TEMPLATE = 'REPORT_TEMPLATE', // 报表模板
  WORKFLOW_ACTION = 'WORKFLOW_ACTION', // 流程动作
  WORKFLOW_CONDITION = 'WORKFLOW_CONDITION', // 流程条件
  WORKFLOW_NODE = 'WORKFLOW_NODE', // 流程节点
}

// 资源类型定义
export interface ResourceTypeDefinition {
  id: string;
  name: string;
  code: string;
  category: ResourceCategory;
  businessType?: BusinessResourceType;
  technicalType?: TechnicalResourceType;
  description?: string;
  icon?: string;
  color?: string;
  isActive: boolean;
  metadata?: Record<string, any>;
  createdAt: string;
  updatedAt: string;
}

// 资源子类型
export interface ResourceSubType {
  id: string;
  parentTypeId: string;
  name: string;
  code: string;
  description?: string;
  attributes: ResourceAttribute[];
  businessTypes: string[];
  isActive: boolean;
  createdAt: string;
  updatedAt: string;
}

// 资源属性定义
export interface ResourceAttribute {
  id: string;
  name: string;
  code: string;
  type: AttributeType;
  dataType: AttributeDataType;
  isRequired: boolean;
  defaultValue?: any;
  validation?: AttributeValidation;
  options?: AttributeOption[];
  description?: string;
  order: number;
  isActive: boolean;
}

// 属性类型
export enum AttributeType {
  BASIC = 'BASIC',
  BUSINESS = 'BUSINESS',
  CUSTOM = 'CUSTOM',
  TECHNICAL = 'TECHNICAL',
}

// 属性数据类型
export enum AttributeDataType {
  BOOLEAN = 'BOOLEAN',
  DATE = 'DATE',
  DATETIME = 'DATETIME',
  ENUM = 'ENUM',
  FILE = 'FILE',
  JSON = 'JSON',
  NUMBER = 'NUMBER',
  STRING = 'STRING',
  URL = 'URL',
}

// 属性验证规则
export interface AttributeValidation {
  minLength?: number;
  maxLength?: number;
  minValue?: number;
  maxValue?: number;
  pattern?: string;
  required?: boolean;
  unique?: boolean;
  customRule?: string;
}

// 属性选项
export interface AttributeOption {
  value: string;
  label: string;
  description?: string;
  isDefault?: boolean;
}

// 资源归属
export interface ResourceOwnership {
  id: string;
  resourceId: string;
  tenantId: string;
  businessType: string;
  department?: string;
  team?: string;
  owner?: string;
  manager?: string;
  isPrimary: boolean;
  startDate: string;
  endDate?: string;
  createdAt: string;
  updatedAt: string;
}

// 资源版本
export interface ResourceVersion {
  id: string;
  resourceId: string;
  version: string;
  versionType: VersionType;
  description?: string;
  changes?: VersionChange[];
  isActive: boolean;
  isPublished: boolean;
  publishedBy?: string;
  publishedAt?: string;
  createdAt: string;
  updatedAt: string;
}

// 版本类型
export enum VersionType {
  ALPHA = 'ALPHA',
  BETA = 'BETA',
  MAJOR = 'MAJOR',
  MINOR = 'MINOR',
  PATCH = 'PATCH',
}

// 版本变更
export interface VersionChange {
  field: string;
  oldValue?: any;
  newValue?: any;
  changeType: ChangeType;
  description?: string;
}

// 变更类型
export enum ChangeType {
  ADD = 'ADD',
  DELETE = 'DELETE',
  DEPRECATE = 'DEPRECATE',
  UPDATE = 'UPDATE',
}

// 统一资源注册表
export interface ResourceRegistry {
  id: string;
  resourceId: string;
  typeId: string;
  subTypeId?: string;
  name: string;
  code: string;
  category: ResourceCategory;
  businessTypes: string[];
  attributes: ResourceAttributeValue[];
  ownership: ResourceOwnership[];
  versions: ResourceVersion[];
  status: ResourceStatus;
  tags: string[];
  metadata: Record<string, any>;
  isActive: boolean;
  createdAt: string;
  updatedAt: string;
}

// 资源属性值
export interface ResourceAttributeValue {
  attributeId: string;
  value: any;
  lastUpdated: string;
  updatedBy: string;
}

// 资源状态
export enum ResourceStatus {
  ACTIVE = 'ACTIVE',
  ARCHIVED = 'ARCHIVED',
  DEPRECATED = 'DEPRECATED',
  DRAFT = 'DRAFT',
  INACTIVE = 'INACTIVE',
}

// 查询参数
export interface CatalogQueryParams {
  category?: ResourceCategory;
  businessType?: string;
  technicalType?: string;
  keyword?: string;
  status?: ResourceStatus;
  isActive?: boolean;
  pageNo?: number;
  pageSize?: number;
}

// API响应
export interface CatalogResponse {
  list: ResourceRegistry[];
  total: number;
  pageNo: number;
  pageSize: number;
}
